package com.ruiyu.IM;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.ruiyu.IM.fragment.FriendsFragment;
import com.ruiyu.IM.fragment.MessageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 瑞玉 on 2016/1/15.
 */
public class MainActivity extends FragmentActivity {

    private ViewPager mPager;
    private TextView mMessage;
    private TextView mFriends;
    private List<Fragment> pages;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        initView();

        pages = new ArrayList<>();
        pages.add(new FriendsFragment());
        pages.add(new MessageFragment());
        MyPageAdapter adapter = new MyPageAdapter(this.getSupportFragmentManager());
        mPager.setAdapter(adapter);

    }

    private void initView() {

        mPager = (ViewPager) findViewById(R.id.vp_page);
        mMessage = (TextView) findViewById(R.id.tv_message);
        mFriends = (TextView) findViewById(R.id.tv_friends);
    }


    private class MyPageAdapter extends FragmentPagerAdapter {
        public MyPageAdapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public Fragment getItem(int position) {
            return pages.get(position);
        }

        @Override
        public int getCount() {
            return pages.size();
        }
    }
}
